/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.jiujiudevice.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.boxin.ims.modules.jiujiudevice.entity.JiuInkRecord;
import com.boxin.ims.modules.jiujiudevice.service.JiuInkRecordService;

/**
 * 墨盒使用记录Controller
 * @author sxh
 * @version 2018-10-26
 */
@Controller
@RequestMapping(value = Global.ADMIN_PATH+"/jiujiudevice/jiuInkRecord")
public class JiuInkRecordController extends BaseController {

	@Autowired
	private JiuInkRecordService jiuInkRecordService;
	
	@ModelAttribute
	public JiuInkRecord get(@RequestParam(required=false) Long id) {
		if (id != null){
			return jiuInkRecordService.get(id);
		}else{
			return new JiuInkRecord();
		}
	}
	
	@RequiresPermissions("jiujiudevice:jiuInkRecord:view")
	@RequestMapping(value = {"list", ""})
	public String list(JiuInkRecord jiuInkRecord, HttpServletRequest request, HttpServletResponse response, Model model) {
		User user = UserUtils.getUser();
        Page<JiuInkRecord> page = jiuInkRecordService.find(new Page<JiuInkRecord>(request, response), jiuInkRecord); 
        model.addAttribute("page", page);
		return "modules/jiujiudevice/jiuInkRecordList";
	}

	@RequiresPermissions("jiujiudevice:jiuInkRecord:view")
	@RequestMapping(value = "form")
	public String form(JiuInkRecord jiuInkRecord, Model model) {
		model.addAttribute("jiuInkRecord", jiuInkRecord);
		return "modules/jiujiudevice/jiuInkRecordForm";
	}

	@RequiresPermissions("jiujiudevice:jiuInkRecord:edit")
	@RequestMapping(value = "save")
	public String save(JiuInkRecord jiuInkRecord, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, jiuInkRecord)){
			return form(jiuInkRecord, model);
		}
		jiuInkRecordService.save(jiuInkRecord);
		addMessage(redirectAttributes, "保存墨盒使用记录'" + jiuInkRecord + "'成功");
		return "redirect:"+Global.ADMIN_PATH+"/modules/jiujiudevice/jiuInkRecord/?repage";
	}
	
	@RequiresPermissions("jiujiudevice:jiuInkRecord:edit")
	@RequestMapping(value = "delete")
	public String delete(Long id, RedirectAttributes redirectAttributes) {
		jiuInkRecordService.delete(id);
		addMessage(redirectAttributes, "删除墨盒使用记录成功");
		return "redirect:"+Global.ADMIN_PATH+"/modules/jiujiudevice/jiuInkRecord/?repage";
	}

}
